<?php
General::getTpl()->assign('extraTitle',"Styles");

if(!Admin::checkPermission('canManageStyles')) {
	General::ouputMessage('Fehler','Sie haben nicht gen&uuml;gend Rechte um diese Seite zu betrachten');
}else{
	General::getTpl()->assign('defaultStyle',Settings::getInstance()->getSetting('general.defaultStyle'));
	
	if(isset($_GET['setFolder']) && file_exists("./templates/".$_GET['setFolder']."/style.xml")) {
		Settings::getInstance()->changeSetting("general.defaultStyle",DB::parseVar($_GET['setFolder']));
		General::getTpl()->assign('defaultStyle',$_GET['setFolder']);
		
		General::ouputMessage("Erfolgreich","Der Standard-Style wurde erfolgreich gewechselt.","form");
	}
	
	
	
	$styles = array();
	
	$DH = dir("./templates/");
	while ($styleDir = $DH->read()) {
    	if (preg_match('/^..?$/', $styleDir)) continue;
       	
    	// Check for style.xml
    	if(!is_dir("./templates/".$styleDir)) continue;
    	if(file_exists("./templates/".$styleDir."/style.xml")) {
    		$xml = simplexml_load_file("./templates/".$styleDir."/style.xml");
    		$styleData['name'] = $xml->name;
    		$styleData['author'] = $xml->author;
    		$styleData['authorUrl'] = $xml->authorUrl;
    		$styleData['folder'] = $styleDir;
    		$styles[] = $styleData;
    	}
	}
    $DH->close();
    
   
	General::getTpl()->assign('styles',$styles);
	
	General::getTpl()->assign('body',
		General::getTpl()->fetch('../admin/styles.html'));
}
?>